home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / SHUTDOWN.CMD < prev    next >
OS/2 REXX Batch file  |  1993-11-16  |  3KB  |  94 lines

  1. :: ShutDown.cmd - A weird script that uses many instances of CEnvi
  2. ::                To shutdown the system.
  3. ::
  4. :: The ShutDown.cmd Algorithm: First, lazy writing is turned off
  5. :: and some processes are killed if they are running.  You can put
  6. :: any batch commands in this first section.  The ones here represent
  7. :: some processes that do not respond to the PMshell's shutdown
  8. :: procedure and would otherwise need to be manually terminated.
  9. cache /LAZY:OFF
  10. CALL Kill "Background Randomizer"
  11. CALL Kill hook_kbs
  12. CALL Kill os2execd
  13. CALL Kill MemStat
  14. CALL Kill MAXP
  15. CALL Kill NomBBS
  16. CALL Kill "NumLock Forever"
  17.  
  18. :: Next, start the first CEnvi instance of this program, which will kill
  19. :: the second instance when the second instance is waiting for keyboard
  20. :: input.  Give this process a couple of seconds to get going
  21. start "KillMe" /N /F /WIN CEnvi #include 'ShutDown.cmd,,,EXIT' KillShutDown()
  22. CEnvi suspend(2000);
  23.  
  24. :: Then start the second CEnvi instance, which will call WinShutdownSystem().
  25. :: Shutdown will try to shut this process itself, and so that is why the
  26. :: first instance was created
  27. start "ShutSystem" /N /B /WIN CEnvi #include 'ShutDown.cmd,,,EXIT' ShutDown()
  28.  
  29. :: Finally, exit ShutDown.cmd so that the system shutdown doesn't bother it.
  30. :: All of the code below EXIT is used by the CEnvi calls of this source.
  31. EXIT
  32.  
  33.  
  34. ShutDown()  // Execute the WinShutdownSystem() function
  35. {
  36.    // Give the shell that started this process time to EXIT
  37.    suspend(3000);
  38.  
  39.    // Get Msg Queue of this window
  40.    #define ORD_WIN32QUERYWINDOWULONG   843
  41.    #define QWL_HMQ   (-4)
  42.    MsgQueue = DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWULONG,BIT32,CDECL,
  43.                           Info().WinHandle,QWL_HMQ);
  44.  
  45.    // Call WinShutdownSystem()
  46.    #define  ORD_WIN32SHUTDOWNSYSTEM 149
  47.    DynamicLink("PMWP",ORD_WIN32SHUTDOWNSYSTEM,BIT32,CDECL,
  48.                Info().hab,MsgQueue);
  49. }
  50.  
  51. KillShutDown() // Kill the ShutDown procedure because WinShutdwnSystem()
  52. {              // will try to get stuck getting rid of that window
  53.    // Increase priority of this process because the shutdown modal dialog
  54.    // can tak up a LOT of time
  55.    #define ORD_DOS32SETPRIORITY  236
  56.    #define PRTYC_TIMECRITICAL 3
  57.    DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  58.                 1/*all threads*/,PRTYC_TIMECRITICAL,0,0);
  59.  
  60.    // Wait for this focus window to change from this one. That's how well
  61.    // know that the kill message is present
  62.    printf("Waiting for \"ShutSystem\" to need shutting down...");
  63.    Focus = GetFocusWindow();
  64.    do {
  65.       suspend(1000);
  66.    } while ( Focus == GetFocusWindow() );
  67.  
  68.    // Call command to kill the ShutDown session so it doesn't start on reboot
  69.    printf("\nKill ShutSystem\n");
  70.    system("Kill ShutSystem");
  71.  
  72.    // Right now a dialog box is asking if we want to kill "SHUTDOWN". Send
  73.    // it the 'Y' keystroke and get out of here
  74.    PostKeystroke('Y');
  75. }
  76.  
  77. PostKeystroke(KeyStroke)
  78. {
  79.    #define KC_CHAR         0x0001
  80.    #define KC_LONEKEY      0x0100
  81.    Param1 = ((KC_CHAR | KC_LONEKEY)) | (1 << 16);
  82.  
  83.    #define ORD_WIN32POSTMSG   919
  84.    #define WM_CHAR   0x007a
  85.    DynamicLink("PMWIN",ORD_WIN32POSTMSG,BIT32,CDECL,
  86.                GetFocusWindow(),WM_CHAR,Param1,KeyStroke);
  87. }
  88.  
  89. GetFocusWindow()  // return handle of active focus window
  90. {
  91.    #define ORD_WIN32QUERYFOCUS   817
  92.    return DynamicLink("PMWIN",ORD_WIN32QUERYFOCUS,BIT32,CDECL,1);
  93. }
  94.